package com.dq.domain.record;

import com.dq.vo.baseVo.VO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.orders.Orders;
import com.dq.domain.orders.UserOrder;
import com.dq.domain.org.Org;
import com.dq.domain.sys.user.user.base.SysUser;
import com.dq.utils.TimeUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import java.math.BigDecimal;

/**
 * @author liuhui
 * @date 2019/11/20 0020 16:00:15
 */
@Data
@Entity
@ApiModel("欠款记录")
public class ArrearsRecord extends BaseEntity implements VO.ToVO {

    @ApiModelProperty("欠款编号")
    protected String arrearsNo;

    @ApiModelProperty("欠款用户")
    @ManyToOne
    protected SysUser sysUser;

    @ApiModelProperty("所欠门店")
    @ManyToOne
    protected Org sysDept;

    @ApiModelProperty("欠款关联订单")
    @ManyToOne
    protected Orders orders;

    @ApiModelProperty("欠款状态")
    @Enumerated(EnumType.ORDINAL)
    protected ArrearsStatus arrearsStatus;

    public enum ArrearsStatus{
        notPay("未支付"),
        alreadyPay("已支付");
        public String name;

        ArrearsStatus(String name){
            this.name = name;
        }
    }



    @Data
    @ApiModel(value = "欠款记录视图")
    public static class Vo implements VO {

    }

    @Data
    @ApiModel(value = "门店端欠款记录视图")
    public static class OrgListVo{
        @ApiModelProperty("欠款id")
        protected Long id;
        @ApiModelProperty("欠款编号")
        protected String arrearsNo;
        @ApiModelProperty("欠款时间")
        protected String arrearsTime;
        @ApiModelProperty("欠款状态")
        protected String arrearsStatus;
        @ApiModelProperty("欠款状态en")
        protected ArrearsStatus arrearsStatusEN;

        @ApiModelProperty("顾客ID")
        protected Long wxUserId;
        @ApiModelProperty("顾客编号")
        protected String cardNo;
        @ApiModelProperty("欠款顾客姓名")
        protected String getUserRealcName;

        @ApiModelProperty("门店名")
        protected String orgName;

        @ApiModelProperty("欠款金额")
        protected BigDecimal arrearsAmount;
        @ApiModelProperty("关联订单单号")
        protected String ordersNo;
    }

    public OrgListVo toOrgListVo(){
        ArrearsRecord.OrgListVo orgListVo = new ArrearsRecord.OrgListVo();
        orgListVo.id = this.getId();
        orgListVo.arrearsNo = fmt(this.getArrearsNo());
        orgListVo.arrearsStatus = fmt(this.getArrearsStatus().name);
        orgListVo.arrearsStatusEN = this.arrearsStatus;
        orgListVo.arrearsTime = fmt(this.getCreateTime(), TimeUtil.YYYY_MM_DD_HH_MM_SS);

        orgListVo.getUserRealcName = this.getSysUser() == null ? "" : this.getSysUser().getUserRealcName();
        orgListVo.cardNo = this.getSysUser() == null ? "" : this.getSysUser().getCardNo();
        orgListVo.wxUserId = this.getSysUser() == null ? null : this.getSysUser().getId();

        orgListVo.orgName = fmt(this.getSysDept().getSimpleName());

        UserOrder userOrder = (UserOrder) this.getOrders();
        orgListVo.arrearsAmount = fmt(userOrder.getArrearsPrice());
        orgListVo.ordersNo = fmt(userOrder.getOrdersNo());

        return orgListVo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();

        return vo;
    }
}
